package scheduledtasks.parscorn;

import java.util.Calendar;
import java.util.Date;


/**
 * 【解析链]
 *
 * @author tiny
 * @version 1.0
 * @company bc
 * @copyright (c) 2022 bcInc. All rights reserved.
 * @date 2022-11-08 16:00:26
 * @since  构建表达式的责任解析链,他是从后往前的解析
 */
public class ParsUntil {
    public static String getcron(String cron,int i){
        String cronstr[]=cron.split(" ");
        return cronstr[i];
    }

    /*  1IS  1, 0 IS 0/11    */
    public static Integer getcronParm(String cron){
        String cronstr[]=cron.split("/");
        if(cronstr.length==1){
            return 1;
        }
        return 0;
    }
    public static String getWeekOfDate(Date dt) {
        String[] weekDays = {"7", "1", "2", "3", "4", "5", "6"};
        Calendar cal = Calendar.getInstance();
        cal.setTime(dt);
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (w < 0)
            w = 0;
        return weekDays[w];
    }


    public static  ParseAbstract getp(){
        WorkParse workParse=  new WorkParse();
        WeekParse weekParse = new WeekParse();
        workParse.setParseAbstract(weekParse);

        MonthParse monthParse = new MonthParse();
        weekParse.setParseAbstract(monthParse);

        DayParse dayParse = new DayParse();
        monthParse.setParseAbstract(dayParse);

        HoursParse hoursParse = new HoursParse();
        dayParse.setParseAbstract(hoursParse);

        MinuteParse minuteParse=new MinuteParse();
        hoursParse.setParseAbstract(minuteParse);

        SecondParse secondParse=new SecondParse();
        minuteParse.setParseAbstract(secondParse);

        return workParse;



    }

}
